import javax.xml.stream.events.EndDocument;

/**
 * Created by losor on 2017/3/16.
 */
public class _441_ArrangingCoins {
    public static void main(String[] args) {
        _441_ArrangingCoins a = new _441_ArrangingCoins();
        System.out.println(a.arrangeCoins(0));
    }

    public int arrangeCoins(int n) {
        long sum = 0;
        for (int i = 0; i < n; i++) {
            sum += i ;
            if (sum>n){
                return i-1;
            }
            else if(sum == n){
                return i;
            }
        }
        return 0;
    }
    public int arrangeCoins1(int n) {
        int left = 0;
        int right = n;
        int mid = 0;
        while(left <= right){
            mid = (left + right) >>> 1;
            if (0.5 * mid * mid + 0.5 * mid > n){
                right = mid - 1;
            }
            else{
                left = mid + 1;
            }

        }
        return left - 1;
    }
}
